package idTest;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

public class Demo {

    public static void main(String[] args) {
        Set<Long> set = new CopyOnWriteArraySet<>();

        List<Long> list = new ArrayList<>();
        for (int i = 0; i < 30000; i++) {
            new Thread(() -> {
                long id = IdGenerator.getIdGenerator().nextId();
                set.add(id);
                list.add(id);
            }).start();
        }
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(set.size());
        System.out.println("list:" + list.size());
    }

    @Test
    public void demo01() {
        List<Long> list = new ArrayList<>();
        Long a = 100L;
        list.add(a);
        list.add(a);
        list.add(a);
        System.out.println(list.size());
    }

    @Test
    public void demo02() {
        Set<Long> set = new HashSet<>();
        for (int i = 0; i < 30000; i++) {
            new Thread(() -> {
                long id = IdGenerator.getIdGenerator().nextId();
                set.add(id);
            }).start();
        }
        System.out.println(set.size());
    }
}
